import { Test } from '@nestjs/testing'
import { AuthModuleOptions } from '../interfaces/auth-options.interface'
import { CryptographyService } from '../services/cryptography.service'
import crypto from 'crypto'
import { AUTH_OPTIONS } from '../auth.constants'
import { beforeEach, describe, expect, test } from 'vitest'

describe('CryptographyService', () => {
  let cryptographyService: CryptographyService
  const options: Pick<AuthModuleOptions, 'encryptionSalt' | 'encryptionSecret'> = {
    encryptionSecret: crypto.randomBytes(32).toString('hex'),
    encryptionSalt: crypto.randomBytes(16).toString('hex'),
  }

  beforeEach(async () => {
    const testModule = await Test.createTestingModule({
      providers: [
        {
          provide: AUTH_OPTIONS,
          useValue: options,
        },
        CryptographyService,
      ],
    }).compile()

    cryptographyService = testModule.get(CryptographyService)
  })

  test('aes', () => {
    const data = 'hello!'
    const encrypted = cryptographyService.aesEncrypt(data)
    const decrypted = cryptographyService.aesDecrypt(encrypted)

    expect(decrypted).toBe(data)
  })
})